-----------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/juanpablouribetrujillo/My Drive (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analys
> is/../logs/Trends_figures.log
  log type:  text
 opened on:  24 Jun 2024, 22:20:48

. * THIS IS THE SCHEME FOR THE GRAPHS. ALL THE GRPHS WILL HAVE THE SAME SCHEME;
. *settings some settings that are common for the set of plots on this dofile;
.  local pdf_plot_settings =      `"
>                                 xmtick(1984(1)2008)
>                                 xlabel(1984(4)2008)
>                                 ylabel(#3,)
>                                 ymticks(##4)
>                                 scale(*1.5) 
>                                 xtitle("")
>                                 ytitle("")
>                                 legend(off)"';

. *scale(*1.3): This rescales the font size of the whole figure;
.         ********************************************************************;
.         use "../data/state_year_all_80_15.dta", clear  ;

. *---------------------------------------------------;
. * - Generate variables and general cleanings ;
. *---------------------------------------------------;
. do "_setup_expenditure.do";

. /******************************************************************
> 
> setup_expenditure.do
> 
> Subroutine to calculate expenditure variables for all analysis programs;
> 
> mt 20190506
> *******************************************************************/
. # delim ;  
delimiter now ;
. * expenditure on length and IRI from SF12a. Check that categories are right. Can we break apart ROW?;
. *conversion factor to get to 10^6 2010 dollars;
. gen deflate= 1/(ppiaco_2010*10);

. *gen deflate= 1;
. *consolidate rural and urban SF12a variables that we need;
. local rur_urb_list      "exp_eng_row_IH                 exp_row_IH              exp_eng_IH              e
> xp_new_cons_IH
>                         exp_relocation_IH               exp_recons_IH           exp_recons_add_IH       e
> xp_recons_noadd_IH
>                         exp_maj_wide_IH                 exp_R3_IH               exp_R3_min_wide_IH      e
> xp_R3_rehab_rest_IH    
>                         exp_R3_resurf_IH
>                         exp_new_bridge_IH exp_bridgereplacement_IH exp_majorbridgerehab_IH exp_minorbridg
> erehab_IH exp_bridge_IH
>                         ";

. foreach exp_var of local rur_urb_list{;
  2.                 replace `exp_var'_urban=cond(`exp_var'_urban==.,0,`exp_var'_urban);
  3.                 replace `exp_var'_rural=cond(`exp_var'_rural==.,0,`exp_var'_rural);
  4.                 gen `exp_var'_all = `exp_var'_urban + `exp_var'_rural;
  5.                 drop `exp_var'_urban `exp_var'_rural;
  6.                 };
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)
(565 real changes made)
(564 real changes made)

. *consolidate SF12a variables into nominal construction and resurfacing for pre and post 1998;
. *NB: exp_new_cons_IH_all and exp_maj_wide_IH_all are common to pre and post 1998 construction;
. gen exp_L_IH_SF12a_n_old=       exp_eng_row_IH_all + exp_new_cons_IH_all + exp_maj_wide_IH_all;

. gen exp_IRI_IH_SF12a_n_old=     exp_recons_IH_all  + exp_R3_IH_all;

.  gen exp_L_IH_SF12a_n_new=      exp_row_IH_all     + exp_eng_IH_all      + exp_new_cons_IH_all  + exp_rel
> ocation_IH_all + exp_maj_wide_IH_all;

.                         gen exp_IRI_IH_SF12a_n_new=     exp_recons_add_IH  + exp_recons_noadd_IH + exp_R3
> _min_wide_IH   + exp_R3_rehab_rest_IH  + exp_R3_resurf_IH;

. * Do the same for bridge expenditure ;
. gen exp_bridge_IH_SF12a_n_new=cond( year>1998,
>                                                                         exp_new_bridge_IH_all+exp_bridger
> eplacement_IH_all+exp_majorbridgerehab_IH_all+exp_minorbridgerehab_IH_all,.);
(931 missing values generated)

.                                                                         gen exp_bridge_IH_SF12a_n_old=con
> d( year<=1998,
>                                                                         exp_bridge_IH_all,.);
(833 missing values generated)

. *diagnostics -- should all be zero -- this test won't work for construction;
. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year>1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |        833    75901.17    142629.8          0    1142287
exp_IRI_IH~d |        833           0           0          0          0

. sum exp_IRI_IH_SF12a_n_new exp_IRI_IH_SF12a_n_old if year<=1998;

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
exp_IRI_IH~w |        931           0           0          0          0
exp_IRI_IH~d |        931    47717.58    68779.22          0     560136

. *consolidate pre and post 1998 variable construction;
. gen exp_IRI_IH_SF12a_n =        cond(year>1998, exp_IRI_IH_SF12a_n_new, exp_IRI_IH_SF12a_n_old);

. gen exp_L_IH_SF12a_n =          cond(year>1998, exp_L_IH_SF12a_n_new, exp_L_IH_SF12a_n_old);

. gen exp_bridge_IH_SF12a_n =             cond(year>1998, exp_bridge_IH_SF12a_n_new, exp_bridge_IH_SF12a_n_
> old);

. *clean up -- save reloacation;
. gen temp = exp_relocation_IH_all;

. gen temp2 =exp_row_IH_all ;

. foreach exp_var of local rur_urb_list{;
  2.                 drop `exp_var'_all;
  3.                 };

.                 drop *_new *_old;

. rename temp exp_relocation_IH_all_n;

.  rename temp2 exp_row_IH_all_n ;

. *calculate total IH and SF12a maintenance;
. gen exp_IH_total_SF12_n = exp_IH_mtn_all + exp_IH_k_all;
(180 missing values generated)

. gen exp_IH_mtn_SF12a_n = exp_IH_total_SF12_n - exp_IRI_IH_SF12a_n - exp_L_IH_SF12a_n -exp_bridge_IH_SF12a
> _n;
(180 missing values generated)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%       -34577        -796329
 5%            0        -387772
10%         4495        -242600       Obs               1,584
25%        13109        -198478       Sum of wgt.       1,584

50%     33878.59                      Mean           108119.7
                        Largest       Std. dev.      250930.4
75%     94553.93        2017193
90%       252167        2062267       Variance       6.30e+10
95%       424198        3278198       Skewness       5.866655
99%      1313969        3303381       Kurtosis         52.087

. replace exp_IH_mtn_SF12a_n= cond(exp_IH_mtn_SF12a_n<0,0,exp_IH_mtn_SF12a_n );
(27 real changes made)

. sum exp_IH_mtn_SF12a_n, d ;

                     exp_IH_mtn_SF12a_n
-------------------------------------------------------------
      Percentiles      Smallest
 1%            0              0
 5%            0              0
10%         4495              0       Obs               1,584
25%        13109              0       Sum of wgt.       1,584

50%     33878.59                      Mean           109822.3
                        Largest       Std. dev.      248973.5
75%     94553.93        2017193
90%       252167        2062267       Variance       6.20e+10
95%       424198        3278198       Skewness       6.026436
99%      1313969        3303381       Kurtosis       53.45254

. ;
. *convert to real 2010 USD 10^6;
. *NB: deflate calculated in calling program;
. rename app_IH app_IH_n;

. rename exp_IH_mtn_all exp_IH_mtn_SF12_n;

. ren rev_grand_total_mt rev_grand_total_mt_n;

. ren rev_total_h rev_total_h_n;

. ren rev_total_mt rev_total_mt_n ;

. ren rev_total_m_fuel_h rev_total_m_fuel_h_n ;

. local real_list "exp_IH_total_SF12 exp_IH_mtn_SF12a exp_IRI_IH_SF12a exp_L_IH_SF12a app_IH exp_IH_mtn_SF1
> 2 exp_relocation_IH_all 
>                                  rev_grand_total_mt rev_total_h rev_total_mt rev_total_m_fuel_h
>                                  exp_bridge_IH_SF12a exp_row_IH_all
>                                  ";

. foreach exp_var of local real_list{;
  2.                 gen `exp_var'_r=deflate*`exp_var'_n;
  3.                 drop `exp_var'_n;
  4.                 };
(180 missing values generated)
(180 missing values generated)
(900 missing values generated)
(180 missing values generated)
(996 missing values generated)
(228 missing values generated)
(996 missing values generated)
(228 missing values generated)

.         forvalues i=1(1)5{;
  2.                                 gen deflate_L`i'= 1/(ppiaco_2010_L`i'*10);
  3.                 ren L`i'FHWA_apport_LW L`i'FHWA_apport_LW_n;
  4.                 gen L`i'FHWA_apport_LW_r=deflate_L`i'*L`i'FHWA_apport_LW_n;
  5.                 drop L`i'FHWA_apport_LW_n;
  6. };
(132 missing values generated)
(180 missing values generated)
(228 missing values generated)
(276 missing values generated)
(324 missing values generated)

.                                                 *label and drop superflous expenditure data;
. label var       exp_IH_total_SF12_r     "Total IH exp SF12 real";

. label var       exp_IH_mtn_SF12_r       "Total IH maint exp SF12 real";

. label var       exp_IH_mtn_SF12a_r      "Total IH maint exp SF12a real";

.  label var      exp_IRI_IH_SF12a_r      "Total IH IRI exp SF12a real";

.  label var      exp_L_IH_SF12a_r        "Total IH L exp SF12a real";

. label var       app_IH_r                "Total IH approp real";

. label var       exp_relocation_IH_all   "Total IH exp relocation, >1998";

. label var   rev_grand_total_mt_r          "Total revenue mass transit account real [source: FE9 p2 ]";

. label var   rev_total_mt_r        "Total revenue highway and mass transit account real [source: FE9 p2 ]"
> ;

. label var   rev_total_h  "Total revenue highway account real [source: FE9 p2 ]";

. label var rev_total_m_fuel_h                     "Total Revenue motor fuel  (Highway motor fuel) [source:
>  FE9 p1 ]";

.         *drop exp_IH_k_rural-exp_subtotal_mtn_urban;
. exit;

end of do-file

. do "_cleaning_and_new_variables.do";

. 
. 
. 
. 
. # d ; 
delimiter now ;
. *label variables to mathc the names in the tables ;
. label var exp_L_IH_SF12a_r "\(I^{L}_{st} \)";

. label var  exp_IRI_IH_SF12a_r "\( Y^L\:in\:IRI \)";

. label var  exp_IH_mtn_SF12a_r "\( Y^L\: in\: Maint.\)";

. *make lagged expenditure and appropriations;
. sort state year;

. gen L1exp_L_IH_SF12a_r=cond(
>                         state[_n]==year[_n-1],
>                         year[_n-1]==year[_n]-1,
>                         exp_L_IH_SF12a_r[_n-1],.);
(1 missing value generated)

. gen L5app_IH_r=cond(
>                         state[_n]==year[_n-5],
>                         year[_n-5]==year[_n]-5,
>                         app_IH_r[_n-5],.);
(901 missing values generated)

.                         gen L1app_IH_r=cond(
>                         state[_n]==year[_n-1],
>                         year[_n-1]==year[_n]-1,
>                         app_IH_r[_n-1],.);
(900 missing values generated)

.                                                                         *calculate first differences in m
> iles and IRI;
. *local D_vars "u_iri_IH u_iri_urban u_iri_rural u_lane_miles_IH u_lane_miles_rural u_lane_miles_urban";
. local D_vars u_lane_miles_IH  u_lane_miles_rural u_lane_miles_urban u_miles_IH;

. sort state year;

. foreach varname of local D_vars{;
  2.                 gen D`varname'=cond(
>                                 state[_n]==state[_n-1]&
>                                 `varname'[_n-1]!=.&`varname'[_n]!=.&
>                                 `varname'[_n-1]!=0&`varname'[_n]!=0&
>                                 year[_n-1]==year[_n]-1,
>                                 `varname'[_n]-`varname'[_n-1],.);
  3.                                 };
(342 missing values generated)
(402 missing values generated)
(346 missing values generated)
(342 missing values generated)

.                                 *Create average width of lane miles ;
. gen u_width_IH= u_lane_miles_IH/u_miles_IH;
(293 missing values generated)

. label var u_width_IH "Avergae width of lanes";

.                                 *create expantion lanes in existing segments and new segments;
.                                 gen Du_expantion_miles_IH=cond(
>                                 state[_n]==state[_n-1]&
>                                 u_lane_miles_IH[_n-1]!=.&u_lane_miles_IH[_n]!=.&
>                                 u_miles_IH[_n-1]!=.&u_miles_IH[_n]!=.&
>                                 year[_n-1]==year[_n]-1,
>                                 Du_lane_miles_IH - Du_miles_IH*u_width_IH[_n-1],
>                                 .);
(342 missing values generated)

. *replace Du_expantion_miles_IH=0 if Du_expantion_miles_IH<0;
.                         label var Du_expantion_miles_IH "Expansion miles";

.                                 //note: The assumption to create this variable is that the new miles occu
> rs at mean width ;
> 
> gen sh_new_lm=cond(state[_n]==state[_n-1]&
>                                 u_lane_miles_IH[_n-1]!=.&u_lane_miles_IH[_n]!=.&
>                                 u_miles_IH[_n-1]!=.&u_miles_IH[_n]!=.&
>                                 year[_n-1]==year[_n]-1, Du_miles_IH*u_width_IH/Du_lane_miles_IH,.) ;
(494 missing values generated)

. *replace sh_new_lm=1 if Du_expantion_miles_IH==0 & Du_lane_miles_IH>0;
. label var sh_new_lm "Share of new lane miles in new segments";

. gen sh_exp_lm= Du_expantion_miles_IH/Du_lane_miles_IH;
(494 missing values generated)

. label var sh_exp_lm "Share of new lane miles that are expantions";

. *dropping missing d_lane_miles saves trouble later;
. * keep all years with lagge appropriations;
. * N.B.: Nothing strange here.  SF12a missing <1984;
. drop if year>2008|year<1980;
(343 observations deleted)

. drop if u_lane_miles_IH==.;
(0 observations deleted)

. drop if u_lane_miles_IH==0;
(0 observations deleted)

. drop if u_lane_miles_IH<0;
(0 observations deleted)

. *drop DC;
. drop if state==11;
(29 observations deleted)

. * time, for estimating trends;
. gen time =year-1984;

. gen time2 =time^2;

. gen time3 =time^3;

. label var time2 "\(time^2\)" ;

. label var time3 "\(time^3\)" ;

. *TIME TREND DUMMIES;
. gen     periods=1 if  year>=1984&year<=1989;
(1,104 missing values generated)

. replace periods=2 if  year>=1990&year<=1994;
(240 real changes made)

. replace periods=3 if  year>=1995&year<=1999;
(240 real changes made)

. replace periods=4 if  year>=2000&year<=2004;
(240 real changes made)

. replace periods=5 if  year>=2005&year<=2008;
(192 real changes made)

. tab year periods, m ;

           |                              periods
 Book year |         1          2          3          4          5          . |     Total
-----------+------------------------------------------------------------------+----------
      1980 |         0          0          0          0          0         48 |        48 
      1981 |         0          0          0          0          0         48 |        48 
      1982 |         0          0          0          0          0         48 |        48 
      1983 |         0          0          0          0          0         48 |        48 
      1984 |        48          0          0          0          0          0 |        48 
      1985 |        48          0          0          0          0          0 |        48 
      1986 |        48          0          0          0          0          0 |        48 
      1987 |        48          0          0          0          0          0 |        48 
      1988 |        48          0          0          0          0          0 |        48 
      1989 |        48          0          0          0          0          0 |        48 
      1990 |         0         48          0          0          0          0 |        48 
      1991 |         0         48          0          0          0          0 |        48 
      1992 |         0         48          0          0          0          0 |        48 
      1993 |         0         48          0          0          0          0 |        48 
      1994 |         0         48          0          0          0          0 |        48 
      1995 |         0          0         48          0          0          0 |        48 
      1996 |         0          0         48          0          0          0 |        48 
      1997 |         0          0         48          0          0          0 |        48 
      1998 |         0          0         48          0          0          0 |        48 
      1999 |         0          0         48          0          0          0 |        48 
      2000 |         0          0          0         48          0          0 |        48 
      2001 |         0          0          0         48          0          0 |        48 
      2002 |         0          0          0         48          0          0 |        48 
      2003 |         0          0          0         48          0          0 |        48 
      2004 |         0          0          0         48          0          0 |        48 
      2005 |         0          0          0          0         48          0 |        48 
      2006 |         0          0          0          0         48          0 |        48 
      2007 |         0          0          0          0         48          0 |        48 
      2008 |         0          0          0          0         48          0 |        48 
-----------+------------------------------------------------------------------+----------
     Total |       288        240        240        240        192        192 |     1,392 

. label define periods 1 "1984-1989"
>                                         2 "1990-1994"
>                                         3 "1995-1999"
>                                         4 "2000-2004"
>                                         5 "2005-2008";

. label values periods periods;

. # d cr ;
delimiter now cr
. 
. 
end of do-file

. xtset state year;

Panel variable: state (strongly balanced)
 Time variable: year, 1980 to 2008
         Delta: 1 year

. gen Dmiles=d.u_miles_IH ;
(48 missing values generated)

. gen no_exp=cond(exp_L_IH_SF12a_r==. | exp_L_IH_SF12a_r==. | exp_L_IH_SF12a_r<0,1,0);

. *Defining macro variables;
.  global lm_var u_lane_miles_IH u_lane_miles_rural u_lane_miles_urban u_miles_IH
>                                  s_lane_miles_IH s_lane_miles_rural_IH s_lane_miles_urban_IH s_lane_miles
> _rig_IH
>                                  ;

.                                  gen lm_IH_h2O=                 u_lane_miles_IH*sh_h20_10m_s;

.  gen lm_IH_urb=                 u_lane_miles_IH*sh_urb_10m_s;

.  gen lm_IH_elev=        u_lane_miles_IH*sh_elev_10m_s;

.  gen lm_IH_sd_elev=     u_lane_miles_IH*sh_sd_elev_10m_s ;

. gen lm_IH_temp=         u_lane_miles_IH*sh_temp_10m_s;

.  gen lm_IH_precip=      u_lane_miles_IH*sh_precip_10m_s;

.  gen lm_IH_sh_new_lm  =         u_lane_miles_IH*sh_new_lm;
(182 missing values generated)

. gen lm_IH_unionization=         u_lane_miles_IH*unionization;
(960 missing values generated)

. gen lm_IHunionization_Mem_Priv_Cons=    u_lane_miles_IH*unionization_Cov_Priv_Cons ;
(144 missing values generated)

. gen lm_IHunionization_Mem_Total=        u_lane_miles_IH*unionization_Cov_Total ;
(144 missing values generated)

. gen lm_IH_grade = u_lane_miles_IH*s_average_grade_seg_IH ;
(406 missing values generated)

. format lm_IH_grade  %3.2fc;

. gen lm_IH_new=Du_lane_miles_IH*sh_new_lm;
(182 missing values generated)

. *replace lm_IH_new=. if year==1984;
. global comp_var lm_IH_h2O    lm_IH_urb    lm_IH_elev    lm_IH_temp    lm_IH_precip lm_IH_sd_elev lm_IH_gr
> ade lm_IH_new  Dmiles
>                                 sh_h20_10m_s sh_urb_10m_s sh_elev_10m_s sh_temp_10m_s sh_precip_10m_s sh_
> sd_elev_10m_s 
>                                 lm_IH_unionization  lm_IHunionization_Mem_Priv_Cons  lm_IHunionization_Me
> m_Total;

. gen u_inches_IH=        u_iri_IH*u_lane_miles_IH;
(2 missing values generated)

. gen u_inches_urban=     u_iri_urban*u_lane_miles_urban;
(2 missing values generated)

. gen u_inches_rural=     u_iri_rural*u_lane_miles_rural;
(28 missing values generated)

. gen s_inches_IH=        s_iri_IH*s_lane_miles_IH;
(429 missing values generated)

. drop u_iri_IH s_iri_IH s_trucks_av_IH;

. global exp_var   exp_L_IH_SF12a_r exp_IRI_IH_SF12a_r exp_IH_mtn_SF12a_r exp_IH_mtn_SF12_r exp_row_IH_all
>                                  exp_relocation_IH_all_r 
>                                 s_vmt_IH u_vmt_IH s_vmt_trucks_av_IH s_vmt_trucks_peak_IH  u_inches_IH s_
> inches_IH u_inches_rural u_inches_urban
>                                 s_vmt_NHS u_vmt_rural u_vmt_urban;

.         global rev_var rev_grand_total_mt_r rev_total_h_r rev_total_mt_r rev_total_m_fuel_h_r;

. *---------------------------------------------------;
. * - Collapse (year) ;
. *---------------------------------------------------;
. drop if year<1984;
(192 observations deleted)

. *replace 
> 
> *u_lane_miles_IH
> *conversion factor to get to 10^6 2010 dollars;
.                 sort year;

. collapse (mean) asphalt_price Surf_BituminousconcreteAv_ctn10
>  (sum) ${lm_var}
>                            ${comp_var} 
>                            ${exp_var}
>                            ${rev_var}
>                      , by(year);

. *Change in miles as a share of total miles;
.  gen sh_Dmiles= Dmiles/u_miles_IH;

. replace sh_Dmiles=. if year ==1980;
(0 real changes made)

. gen Bituminousconcrete_plm=(Surf_BituminousconcreteAv_ctn10*392/1000000) if year>1990;
(7 missing values generated)

. gen Bituminousconcrete_plm_inv=-Bituminousconcrete_plm^-1 if year>1989;
(7 missing values generated)

. /*
> Since an average lane of interstate is 12 feet wide, resurfacing one lane mile
> requires about 196 cubic yards of asphaltic concrete. At about two tons per cubic yard, this is 392
> tons of paving material.
> 
> */
> 
> preserve ;

. keep Bituminousconcrete_plm_inv Bituminousconcrete_plm year ;

. save  "../intermediate_data/Bituminousconcrete_plm_data", replace;
file ../intermediate_data/Bituminousconcrete_plm_data.dta saved

. restore ;

. twoway (scatter Bituminousconcrete_plm_inv year if year>1989, color(black) msize(*1) m(D)  lw(*2)),
>         ytitle("")
>         xtitle(1990(10)2010)
> xmtick(1990(1)2008)
> ylabel(-100(50)0)
>                                 
>                                 ymticks(##5)
>                                 ymticks(##5)
>                                 scale(*1.5) 
>                                 xtitle("")
>                                 legend(off)
>                                 xtitle("")
>         leg(off);
(note:  named style med not found in class gsize, default attributes used)

.         graph export "${output}/figures/Figure4_Bituminousconcrete_plm_inv.pdf", replace;
file /Users/juanpablouribetrujillo/My Drive
    (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analysis/..//figures/Figure4_Bituminousconcrete_plm_
    > inv.pdf saved as PDF format

. gen unionization=       lm_IHunionization_Mem_Priv_Cons/u_lane_miles_IH;

. gen unionization_total=         lm_IHunionization_Mem_Total/u_lane_miles_IH;

. format  unionization %3.0fc;

. *Generate agg variables;
. foreach x in s u{;
  2.         gen `x'_urban_share_IH= `x'_lane_miles_urban/`x'_lane_miles_IH;
  3.         };
(4 missing values generated)

.  gen s_rig_share_IH=s_lane_miles_rig_IH/s_lane_miles_IH ;
(4 missing values generated)

.  foreach x in h2O urb elev sd_elev temp precip grade new{;
  2.         gen IH_share_`x'=       lm_IH_`x'/u_lane_miles_IH;
  3.         };

. format IH_share_grade %3.1fc;

. format IH_share_h2O %5.3fc;

. format IH_share_urb %5.3fc;

. format IH_share_new  %5.3fc;

. replace IH_share_new=. if year==1980 ;
(0 real changes made)

. *recode zeros to missings;
. foreach varname in exp_L_IH_SF12a_r exp_IRI_IH_SF12a_r exp_IH_mtn_SF12a_r exp_relocation_IH_all_r u_lane_
> miles_IH s_lane_miles_IH s_vmt_IH u_vmt_IH s_vmt_trucks_av_IH s_vmt_trucks_peak_IH u_inches_IH s_inches_I
> H{;
  2.                 replace `varname'=cond(`varname'==0,.,`varname');
  3.         };
(0 real changes made)
(0 real changes made)
(0 real changes made)
(15 real changes made, 15 to missing)
(0 real changes made)
(4 real changes made, 4 to missing)
(4 real changes made, 4 to missing)
(0 real changes made)
(4 real changes made, 4 to missing)
(4 real changes made, 4 to missing)
(9 real changes made, 9 to missing)
(4 real changes made, 4 to missing)

.         replace IH_share_grade=. if year<1992;
(8 real changes made, 8 to missing)

.         gen u_aadt_IH=          (u_vmt_IH/u_lane_miles_IH)/365;

. gen u_aadt_IH_rural=            (u_vmt_rural/u_lane_miles_rural)/365;

. gen u_aadt_IH_urban=            (u_vmt_urban/u_lane_miles_urban)/365;

. gen s_aadt_IH=          (s_vmt_IH/s_lane_miles_IH)/365;
(4 missing values generated)

. gen s_aadt_trucks_av_IH=        s_vmt_trucks_av_IH /s_lane_miles_IH;
(4 missing values generated)

. gen s_aadt_trucks_peak_IH=      s_vmt_trucks_peak_IH/s_lane_miles_IH;
(4 missing values generated)

. gen s_iri_IHnat =       s_inches_IH/s_lane_miles_IH;
(4 missing values generated)

. replace s_iri_IHnat=. if year<1992;
(4 real changes made, 4 to missing)

. gen u_iri_IHnat =       u_inches_IH/u_lane_miles_IH;
(9 missing values generated)

. gen u_iri_IH_urban =    u_inches_urban/u_lane_miles_urban if year>1992;
(9 missing values generated)

. gen u_iri_IH_rural =    u_inches_rural/u_lane_miles_rural  if year>1992;
(9 missing values generated)

. drop u_inches_IH s_inches_IH ;

. *---------------------------------------------------;
. * - Figures (year) ;
. *---------------------------------------------------;
.         replace unionization=. if year<1983;
(0 real changes made)

. replace unionization_total=. if year<1983;
(0 real changes made)

. label var exp_L_IH_SF12a_r              "Construction USD2010";

. label var exp_IRI_IH_SF12a_r    "Resurfacing USD2010";

. label var exp_IH_mtn_SF12a_r    "Maintenance USD2010";

. label var u_lane_miles_IH               "Lane Miles IH, HPMS Universe";

. label var s_lane_miles_IH               "Lane Miles IH, HPMS Sample";

.         label var u_aadt_IH                             "AADT IH, HPMS Universe";

.         label var s_aadt_IH                             "AADT IH, HPMS Sample";

.         label var s_iri_IHnat                   "IRI IH, HPMS Sample";

. label var u_iri_IHnat                   "IRI IH, HPMS Universe";

.   replace u_aadt_IH=u_aadt_IH   /10000;
(25 real changes made)

. replace u_aadt_IH_urban=u_aadt_IH_urban /10000;
(25 real changes made)

. replace u_aadt_IH_rural=u_aadt_IH_rural /10000;
(25 real changes made)

. replace s_aadt_IH=s_aadt_IH/10000;
(21 real changes made)

. replace s_lane_miles_IH=s_lane_miles_IH/1000;
(21 real changes made)

. replace u_lane_miles_IH=u_lane_miles_IH/1000;
(25 real changes made)

. foreach var in lane_miles_IH iri_IHnat {;
  2. twoway  con  u_`var'  year,msize(*.5) lw(*2)
>                 ylabel(#3)
>                 `pdf_plot_settings';
  3.  graph export "${output}/figures/Figure1_`var'.pdf", replace;
  4. };
file /Users/juanpablouribetrujillo/My Drive
    (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analysis/..//figures/Figure1_lane_miles_IH.pdf saved
    as PDF format
file /Users/juanpablouribetrujillo/My Drive
    (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analysis/..//figures/Figure1_iri_IHnat.pdf saved as
    PDF format

. # d ;
delimiter now ;
. foreach var in  aadt_IH  {;
  2. twoway  con  u_`var'  year,msize(*.5) lw(*2)|| 
>             con  s_`var'  year, msize(*.5)  lw(*2)
>                 color(gs5) lwidth(thick) lpattern(dash) 
>                 ,
>                 leg( label(1 "Universe") label(2 "Sample") col(1) ring(0) pos(10) size(*0.5))
>                 `pdf_plot_settings'
>                 ylabel(0.5(0.25)1,format(%3.2fc));
  3.  graph export "${output}/figures/Figure1_`var'.pdf", replace;
  4. };
file /Users/juanpablouribetrujillo/My Drive
    (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analysis/..//figures/Figure1_aadt_IH.pdf saved as
    PDF format

. *---------------------------------------------------;
. *expenditure graph;
. *---------------------------------------------------;
. # d ;
delimiter now ;
. gen sh_row=exp_row_IH_all*100/exp_L_IH_SF12a;

. gen exp1=exp_L_IH_SF12a_r;

. gen exp2=exp1+ exp_IRI_IH_SF12a_r;

. gen exp3=exp2+ exp_IH_mtn_SF12a_r;

. gen prc_expL=exp_L_IH_SF12a_r*100/exp3;

. gen prc_expIRI=exp_IRI_IH_SF12a_r*100/exp3;

. gen prc_expMTN=exp_IH_mtn_SF12a_r*100/exp3;

. gen exp3_alter=exp2+ exp_IH_mtn_SF12_r;

. foreach x in exp1 exp2 exp3{;
  2.         replace `x' =`x'/1000;
  3. };
(25 real changes made)
(25 real changes made)
(25 real changes made)

. twoway  area exp1 year, color(gs2)|| 
>         rarea exp2 exp1 year, color(gs7)|| 
>         rarea exp3 exp2 year, color(gs12)
>         ,  ysc(r(0 25))
>         `pdf_plot_settings'
>         ymtick(0(5)25)
>         ylabel(0(10)25,format(%9.0fc))
>         legend(label(1 "Construction") label(2 "Resurfacing") label(3 "Maintenance") pos(10) ring(0) on s
> ize(*.9));

.  graph export "${output}/figures/Figure1_IH_expenditure.pdf", replace;
file /Users/juanpablouribetrujillo/My Drive
    (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analysis/..//figures/Figure1_IH_expenditure.pdf
    saved as PDF format

. *Revenue graphs ;
.  replace rev_grand_total_mt_r=. if year<1994 ;
(10 real changes made, 10 to missing)

.                            foreach var in  rev_grand_total_mt_r rev_total_h_r rev_total_mt_r    rev_total
> _m_fuel_h_r    {;
  2.                 gen `var'_IH=   `var'*(s_vmt_IH         /s_vmt_NHS)  ;
  3.         gen `var'_IH_per_VMT=`var'_IH*10^6/s_vmt_IH   ;
  4.         *NOTE WE MULTIPLE BY 10^6 to get the revenue in dollars and not thousands USD ;
. };
(10 missing values generated)
(10 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)
(4 missing values generated)

. *BEcause we do not have this data yet;
.  drop   if  year==1997 | year==1998 |year>2008;
(2 observations deleted)

. replace rev_grand_total_mt_r_IH=rev_grand_total_mt_r_IH/1000;
(13 real changes made)

. replace rev_total_m_fuel_h_r_IH=rev_total_m_fuel_h_r_IH/1000;
(19 real changes made)

. replace rev_grand_total_mt_r_IH_per=rev_grand_total_mt_r_IH_per*1000;
(13 real changes made)

. replace  rev_total_m_fuel_h_r_IH_per_VMT= rev_total_m_fuel_h_r_IH_per_VMT*1000;
(19 real changes made)

. *---------------------------------------------------;
. * Table  ;
. *----------------------------------------------------;
. gen selected_years=cond(year==1984 |
>                                                 year==1992 |
>                                                 year==2008,1,0);

. merge 1:1 year using  "../intermediate_data/sh_surface_type_data", nogen ;

    Result                      Number of obs
    -----------------------------------------
    Not matched                            10
        from master                         8  
        from using                          2  

    Matched                                15  
    -----------------------------------------

. keep if selected_years==1                                               ;
(22 observations deleted)

. keep year       
> u_urban_share_IH
> IH_share_urb
> IH_share_grade 
> IH_share_h2O
> IH_share_elev IH_share_new
> lm_sn_d
> sh_surf3 sh_surf2 sh_surf1
> unionization 
> Surf_BituminousconcreteAv_ctn10 ;

. foreach var in u_urban_share_IH IH_share_urb IH_share_h2O IH_share_new sh_surf3 sh_surf2 sh_surf1 {;
  2.         replace `var'=`var'*100;
  3. };
(3 real changes made)
(3 real changes made)
(3 real changes made)
(3 real changes made)
(2 real changes made)
(2 real changes made)
(2 real changes made)

. mkmat u_urban_share_IH
> IH_share_urb
> IH_share_grade 
> IH_share_h2O
> IH_share_elev IH_share_new
> lm_sn_d
> sh_surf3 sh_surf2 sh_surf1
> unionization  , matrix(Table ) rowname(year)    ;

.                                 matrix table=Table'             ;

. matrix list table
> ;

table[11,3]
                   1984       1992       2008
u_urban_sh~H  30.225573  33.505733  42.737083
IH_share_urb  13.134398  13.196169  13.264018
IH_share_g~e          .  1.2421767  1.0634006
IH_share_h2O  7.2632303  7.4212899  7.5057769
IH_share_e~v   456.1871  448.94693  440.07651
IH_share_new  .71326363  .51345551  .16432977
     lm_sn_d          .   6.629723  6.8666761
    sh_surf3          .  21.814884  24.276016
    sh_surf2          .   40.90213  26.830355
    sh_surf1          .  37.282986  48.893627
unionization  24.700144  20.090277  15.927398

.                 esttab matrix(table, fmt( %9.2fc)) using "${output}/tables/Table1_Trends_table.tex", repl
> ace
>                 nomtitles 
>         substitute(  "u_urban_share_IH" "Urban (HPMS)"
> "IH_share_urb" "Urban (NLCD)"
> "IH_share_grade" "Grade (HPMS)"
> "IH_share_h2O" "Water (NLCD)"
> "IH_share_elev" "Elevation"
> "IH_share_new" "\(\%\) New miles"
> "lm_sn_d" "Structural Number"
>  "sh_surf3" "\(\%\) Flexible "
> "sh_surf2" "\(\%\) rigid"
>  "sh_surf1" "\(\%\) composite"
> "unionization"  "Unionization"
> )
>                 nogaps  compress
>                                  title("Lane mile weighted means of network characteristics \label{tab:tr
> ends_table}")
> 
>                          prehead(\begin{table}[H]\centering
> \caption{@title}
>         \begin{tabular}{l*{@span}{c}}\hline
>         ) 
> 
> posthead(\hline)
>         postfoot(
>         \hline
>         \end{tabular}
> \end{table})   ;
(output written to ..//tables/Table1_Trends_table.tex)

. log close;
      name:  <unnamed>
       log:  /Users/juanpablouribetrujillo/My Drive (jp.uribe86@gmail.com)/Research/MyPapers/MTU/JUE/analys
> is/../logs/Trends_figures.log
  log type:  text
 closed on:  24 Jun 2024, 22:21:08
-----------------------------------------------------------------------------------------------------------
